package cn.enjoyedu.direct;

import cn.enjoyedu.RmConst;
import cn.enjoyedu.model.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author huangweiyue
 * @version v1.0
 * @task
 * @description
 * @date Created in 2020-11-03
 * @modifiedBy
 */
@Component
public class DirectSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send() {
        User user = new User();
        user.setName("青");
        user.setPass("111111");
        System.out.println("DirectReceiver发送消息："+user);
        rabbitTemplate.convertAndSend(RmConst.EXCHANGE, RmConst.ROUTING_KEY, user, new CorrelationData(UUID.randomUUID().toString()));

        String msg = "hello qing";
        System.out.println("DirectReceiver发送消息："+ msg);
        rabbitTemplate.convertAndSend(RmConst.EXCHANGE, RmConst.ROUTING_KEY, msg);
    }
}
